//
//  ClassmateDetailViewController.m
//  AndCampus
//
//  Created by 史宵宵 on 2017/12/29.
//  Copyright © 2017年 史宵宵. All rights reserved.
//

#import "ClassmateDetailViewController.h"
#import "NewsTalkViewController.h"

@interface ClassmateDetailViewController ()
@property(nonatomic,strong) UIImageView * headImageView;
@property(nonatomic,strong)UIView * tableHeaderView;

@end

@implementation ClassmateDetailViewController
//- (NSMutableArray *)dataArray{
//    if (!_dataArray) {
//        _dataArray = [[NSMutableArray alloc]init];
//    }
//    return _dataArray;
//}
-(UIView *)tableHeaderView{
    if (!_tableHeaderView) {
        _tableHeaderView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,kScreenW, kScreenH / 7*3)];
        _tableHeaderView.userInteractionEnabled=YES;
    }
    return _tableHeaderView;
}

-(UIImageView *)headImageView{
    if (!_headImageView) {
        _headImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH / 7*3)];
        _headImageView.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; //自动调整view的高度，以保证上边距和下边距不变,自动调整view的宽度，保证左边距和右边距不变
        _headImageView.clipsToBounds=YES;
        _headImageView.userInteractionEnabled=YES;
        _headImageView.contentMode=UIViewContentModeScaleAspectFill;
        _headImageView.backgroundColor = KBACKNAVIGATIONCOLOR;
    }
    return _headImageView;
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    
    return UIStatusBarStyleLightContent;
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    //    [Global setStatusBarBackgroundColor:[UIColor clearColor]];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets=NO;

    CGRect rect = self.view.frame;
    rect.size.height += 64;
    self.tableView.frame = rect;
    
    [self creatHeadView];
    
}
#pragma mark - 发私信
- (void)sendPrivateLetter{
    NewsTalkViewController *newsTalkVC = [[NewsTalkViewController alloc]init];
//    newsTalkVC.newsId = newsInfo.newsId;
    newsTalkVC.friendId = self.classDetailInfo.user_id;
    [self.navigationController pushViewController:newsTalkVC animated:YES];
}
#pragma mark - creatHeadView
- (void)creatHeadView{
    [self.tableHeaderView addSubview:self.headImageView];
    self.tableView.tableHeaderView = self.tableHeaderView;
   
    self.headImageView.image = [UIImage imageNamed:@"MyCenter_bg"];
    
    UIButton *backButton = [[UIButton alloc]init];
    backButton.frame = CGRectMake(0, 20, 50, 50);
    [backButton setImage:[UIImage imageNamed:@"img_back"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.tableHeaderView addSubview:backButton];
    
    if (![self.perentType isEqualToString:@"persent"] && ![self.perentType isEqualToString:@"popularity"]) {
        self.title = @"私信";
        UILabel *titleLabel = [[UILabel alloc]init];
        titleLabel.frame = CGRectMake((kScreenW - 100)/2, 30, 100, 20);
        titleLabel.text = @"私信";
        titleLabel.font = [UIFont systemFontOfSize:18];
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [self.tableHeaderView addSubview:titleLabel];
        
        UIButton *backButton = [[UIButton alloc]init];
        backButton.frame = CGRectMake(kScreenW - 70, 30, 60, 20);
        [backButton setTitle:@"发私信" forState:UIControlStateNormal];
        [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [backButton addTarget:self action:@selector(sendPrivateLetter) forControlEvents:UIControlEventTouchUpInside];
        [self.tableHeaderView addSubview:backButton];
    }
    
    UIImageView *iconImage = [[UIImageView alloc]init];
    iconImage.frame = CGRectMake( (kScreenW - 80)/2, kScreenH / 11 + 20, 80, 80);
    iconImage.clipsToBounds = YES;
    iconImage.layer.cornerRadius = 40;
    iconImage.layer.borderColor = [UIColor whiteColor].CGColor;
    iconImage.layer.borderWidth = 2;
    [self.tableHeaderView addSubview:iconImage];
    
    UILabel *nameLabel = [[UILabel alloc]init];
    nameLabel.frame = CGRectMake(0, CGRectGetMaxY(iconImage.frame)+7, kScreenW, 40);
    nameLabel.font = [UIFont systemFontOfSize:14];
    nameLabel.numberOfLines = 2;
    nameLabel.textColor = [UIColor whiteColor];
    nameLabel.textAlignment = NSTextAlignmentCenter;
    [self.tableHeaderView addSubview:nameLabel];

    if ([self.perentType isEqualToString:@"popularity"]) {
        nameLabel.text = [NSString stringWithFormat:@"%@\n%@%@",self.popularityInfo.nick_name,self.popularityInfo.schoolName,self.popularityInfo.className];
        [iconImage sd_setImageWithURL:[NSURL URLWithString:self.popularityInfo.icon] placeholderImage:KDEFAULTHEAD];
    }else{
        nameLabel.text = [NSString stringWithFormat:@"%@\n%@ %@",self.classDetailInfo.name,self.classDetailInfo.schoolName,self.classDetailInfo.className];
        [iconImage sd_setImageWithURL:[NSURL URLWithString:self.classDetailInfo.icon] placeholderImage:KDEFAULTHEAD];
    }
    
}
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
        
        UILabel *label = [[UILabel alloc]init];
        label.textColor = KHEADERTITLECOLOR;
        label.tag = 1000;
        label.font = [UIFont systemFontOfSize:15];
        label.frame = CGRectMake(20, 12, 40,20);
        [cell.contentView addSubview:label];
        
        UILabel *detailLabel = [[UILabel alloc]init];
        detailLabel.frame = CGRectMake(CGRectGetMaxX(label.frame) + 10, 12, 200,20);
        detailLabel.textColor = KTEXTMAINCOLOR;
        detailLabel.tag = 1100;
        detailLabel.font = [UIFont systemFontOfSize:15];
        [cell.contentView addSubview:detailLabel];
    }
    NSArray *textArray = @[@"昵称",@"星座",@"生日",@"邮箱"];
    
    UILabel *label = [cell.contentView viewWithTag:1000];
    label.text = textArray[indexPath.row];

    UILabel *detailLabel = [cell.contentView viewWithTag:1100];
    if ([self.perentType isEqualToString:@"popularity"]) {
        switch (indexPath.row) {
            case 0:
                detailLabel.text = self.popularityInfo.nick_name;
                break;
            case 1:
                detailLabel.text = self.popularityInfo.constellation;
                break;
            case 2:
                detailLabel.text = self.popularityInfo.birthdate;
                break;
            case 3:
                detailLabel.text = self.popularityInfo.email;
                break;
            default:
                break;
        }
    }else{
        switch (indexPath.row) {
            case 0:
                detailLabel.text = self.classDetailInfo.nick_name;
                break;
            case 1:
                detailLabel.text = self.classDetailInfo.constellation;
                break;
            case 2:
                detailLabel.text = self.classDetailInfo.birthdate;
                break;
            case 3:
                detailLabel.text = self.classDetailInfo.email;
                break;
            default:
                break;
        }
    }
    
    

    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

#define mark - 返回
- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
